﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DotNet.WebUI.Admin
{
    public partial class PwdEdit : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Operate"] = GetQueryString("Operate", "New");

                txtLoginID.Text = Session["DingY.DemoUsers"].ToString();
                txtLoginID.ReadOnly = true;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string _Sql = @"SELECT Count(*)
                    FROM Users
                WHERE LoginID= '{0}'
	                and Pwd ='{1}' ";
            _Sql = string.Format(_Sql, txtLoginID.Text, txtPwd.Text);

            if (Convert.ToInt32(ExecuteScalar(_Sql)) <=0 )
            {
                MessageBox("原密码不正确，请重新输入密码！");
                return;
            }

            if (txtConPwd.Text.Trim() == txtNewPwd.Text.Trim())
            {
                _Sql = @"UPDATE Users 
                    SET Pwd = '{1}'
                    WHERE LoginID = '{0}' ";
                _Sql = string.Format(_Sql,
                    txtLoginID.Text,
                    txtNewPwd.Text);

                if (ExecuteNonQuery(_Sql) >= 1)
                {
                    MessageBox("密码修改成功!");
                }
            }
            else
            {
                MessageBox("新密码和确认密码不相符合，请重新输入密码！");
            }
        }
    }
}